using System;
using NUnit.Framework;
using Rhino.Commons;
using NHibernate;
using NHibernate.Cfg;
using System.Collections.Generic;

namespace NHibernateTests.Tests
{
    [TestFixture]
    public class BaseNhibernateTestFixture
    {
        // set this is the setup methods of derived methods to toggle this behavior
        protected bool _RollBack = true;

        private ISessionFactory SessionFactory { get; set; }
        protected ISession CurrentSession { get; set; }

        [TestFixtureSetUp]
        public virtual void FixtureSetup()
        {
            SessionFactory = new Configuration().Configure().BuildSessionFactory();
        }

        [SetUp]
        public void TestSetUp()
        {
            CurrentSession = SessionFactory.OpenSession();    
            if (_RollBack)
                CurrentSession.BeginTransaction();                    
        }

        [TearDown]
        public void TearDown()
        {
            if (_RollBack)
                CurrentSession.Transaction.Rollback();
            CurrentSession.Close();
        }

    }
}
